<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改安全设置信息</title>
<%@ include file="/WEB-INF/jsp/common/inc.jsp" %>
<script type="text/javascript" src="${_resources}JSON-js-master/json2.js"></script>
<script type="text/javascript">
var numCode='${numCode}';
$(function (){
	$("#safeManagement").validationEngine({
		autoHidePrompt:true,//自动隐藏
		showOnMouseOver:true,//当鼠标移出时触发
		promptPosition:'bottomLeft',//提示信息的位置
		inlineValidation: true,//是否即时验证，false为提交表单时验证,默认true  
		failure : function() {
		    layer.message("验证失败，请检查");
			return false;  
		},//验证失败时调用的函数
		ajaxFormValidation: true,//开始AJAX验证
		success : function() {
		//	$("#addForm").submit();
		}//验证通过时调用的函数 
		//onAjaxFormComplete: ajaxValidationCallback
	});
	var id='${id}';
	var path="${_baseUrl}/safeManagementController/viewInfo";
	$.ajax({    
		type: "POST",    
		async: false,    
		url:path,   
		data:{
			"id":id      
		},    
		dataType:"json",    
		success: function (data) {   
			$("#systemLevel").val(data.systemLevel);
			$("#pwdLocktimes").val(data.pwdLocktimes);
			$("#minimumPwdLength").val(data.minimumPwdLength);
			$("#maximumPwdLength").val(data.maximumPwdLength);
			$("#pwdExpirationTime").val(data.pwdExpirationTime);
			$("#userInactiveTime").val(data.userInactiveTime);
			$("#pwdChangeCycle").val(data.pwdChangeCycle);
			$("#id").val(data.id);
		}   
	});
	
	$("#submit").click(function (){
		var minLength = $("#minimumPwdLength").val();
		var maxLength = $("#maximumPwdLength").val();
		if(numCode == 'tianjin712suo'){
			if($("#pwdLocktimes").val() > 4 ){
				layer.msg("密码锁定次数不能大于4次");
				return;
			}
			if(minLength< 8 ){
				layer.msg("密码长度不能低于8位");
				return;
			}
			if($("#pwdChangeCycle").val() > 30){
				layer.msg("口令更换周期不能高于30天");
				return ;	
			}
		}
		$('#systemLevel').removeAttr("disabled");
		if($("#safeManagement").validationEngine('validate')){
		var options = {
				dataType:"json",
				success:function(json){
					if(json.code == '1'){
						layer.msg(json.message,{shift:5,time:1000},function(){
							parent.refreshTable();
							parent.closeWin();
						});
					}
					if(json.code == '0'){
						layer.msg(json.message);
					}
				},
				error:function(json){
					layer.msg("系统错误,请联系管理员");
				}
			};
		
		if(parseInt(maxLength) < parseInt(minLength)){
			layer.msg("最长密码长度不能小于最短密码长度");
			return false;	
		}
		$("#submit").unbind("click");
		$("#safeManagement").ajaxSubmit(options);
		}
	});
	
	$("#close").click(function (){
		parent.refreshTable();
		parent.closeWin();
	});
});
//智能去掉非法字符
function onlyPutNum(obj) {
    // 先把非数字的都替换掉，除了数字和.    negative属性为true可输入负数
    var negative = $(obj).attr("negative");
    if(obj.value.indexOf("-") == 0 && negative == "true"){
        obj.value = "-"+obj.value.replace(/[^\d.]/g, "");
    }else{
        obj.value = obj.value.replace(/[^\d.]/g, "");
    }
    // 必须保证第一个为数字而不是.
    obj.value = obj.value.replace(/^\./g, "");
    // 保证只有出现一个.而没有多个.
    obj.value = obj.value.replace(/\.{2,}/g, ".");
    // 保证.只出现一次，而不能出现两次以上
    obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$",".");
    var values = obj.value.split('.');
    if (values.length == 2 && String(values[1]).length > 2) {
        obj.value = obj.value.substring(0, obj.value.indexOf('.') + 3);
    }
    //是否允许大于100,为false时大于100时将值替换为100
    var allowGreaterThan = $(obj).attr("allowGreaterThan");
    if(obj.value && (obj.value*1) > 100 && allowGreaterThan == "false"){
         obj.value = 100;
    }
}
</script>
</head>
<body>
	<form name="safeManagement" id="safeManagement" action="${_baseUrl}/safeManagementController/edit" method="post"> 
  	<div>
    <table class="table table-bordered submenu_table">
      <tr>
        <td height="50" width="15%" align="center"><span style="color:#f00">*</span> 系统密级
        	<input type="hidden" id="id" name="id" />
        </td>
        <td width="35%" valign="middle">
        	<div>
        		<select name="systemLevel" disabled="disabled" id="systemLevel" class="func_select" style="width:100%;margin:0">
					<option value='0'>普通</option> 
					<option value='1'>秘密</option> 
					<option value='2'>机密</option>
					<option value='3'>绝密</option>
				</select>
			</div>
		</td>
        <td height="50" width="15%" align="center"><span style="color:#f00">*</span> 密码锁定次数</td>
        <td width="35%" valign="middle">
        	<div class="jbxinxi_s" style="width:auto;">
        		<input type="text" name="pwdLocktimes" id="pwdLocktimes" class="validate[required,custom[positiveInteger]] nav_input"></div>
        </td>
        	
      </tr>
      <tr>
        <td height="50" width="15%" align="center"><span style="color:#f00">*</span> 最短密码长度</td>
        <td width="35%" valign="middle">
	        <div>
	        <input type="text" name="minimumPwdLength" id="minimumPwdLength" class="validate[required,custom[positiveInteger]] nav_input">
	        </div>
	    </td>
        <td height="50" width="15%" align="center"><span style="color:#f00">*</span> 最长密码长度</td>
        <td width="35%" valign="middle">
        	<div><input type="text" name="maximumPwdLength" id="maximumPwdLength" class="validate[required,custom[positiveInteger]] nav_input">
        	</div>
       	</td>
      </tr>
      <tr>
        <td height="50" width="15%" align="center"><span style="color:#f00">*</span> 密码失效时间(天)</td>
        <td width="35%" valign="middle">
        	<div><input type="text" name="pwdExpirationTime"  onkeyup="onlyPutNum(this)" negative="false" id="pwdExpirationTime" class="validate[required] nav_input">
        	</div>
        </td>
        <td height="50" width="15%" align="center"><span style="color:#f00">*</span> 用户非活跃时间(天)</td>
        <td width="35%" valign="middle">
	        <div><input type="text"  onkeyup="onlyPutNum(this)" negative="false" name="userInactiveTime" id="userInactiveTime" class="validate[required] nav_input">
	        </div>
        </td>
      </tr>
      <tr>
        <td height="50" width="15%" align="center"><span style="color:#f00">*</span> 口令更换周期(天)</td>
        <td width="35%" valign="middle">
	        <div><input type="text" name="pwdChangeCycle"  onkeyup="onlyPutNum(this)" negative="false" id="pwdChangeCycle" class="validate[required] nav_input">
	        </div>
        </td>
        <td height="50" width="15%" align="center">&nbsp;</td>
	    <td width="35%" valign="middle">&nbsp;</td>
      </tr>
    </table>
</div>
<div class="permission_an mubanclass_an ma mt30">
	<shiro:hasPermission name="safeManagementController:edit">
        <a href="javascript:;" class="per_baocun" id="submit">保存</a>
   </shiro:hasPermission>
	<shiro:hasPermission name="safeManagementController:close2">
   <a href="javascript:;" class="per_gbi" id="close">关闭</a>
   </shiro:hasPermission>

</div>
	</form> 
</body>
</html>